proc do_banlist {nick chan host} {
  global botnick home bcast

  # Make sure it is a valid channel
  if {![validchan $chan]} {
    putquick "NOTICE $nick :\0034ERROR: $chan is not a valid channel." 
    return 0
  }
  
  # Display bans if available
  if {[banlist $chan] == ""} {
    putquick "NOTICE $nick :\0033I don't have any bans set for $chan"
  } else {
    if {!([banlist $chan] == "")} {
      putlog "!$nick ($host)! banlist $chan"
      putquick "NOTICE $nick :The following bans are set in $chan through the bot (me!):"

      if {$bcast == "1"} {
        putquick "PRIVMSG $home :$nick!$host requested my banlist for $chan....showing.."
      }

	# Number the bans now for easy unbanning
      set counter 1

      foreach newban [banlist $chan] {
        set mask [lindex $newban 0]
        set reason [lindex $newban 1]
        set expire [lindex $newban 2]
        set added [lindex $newban 3]
        set setter [lindex $newban 5]
        set dateexpired [ctime $expire]
        set dateadded [ctime $added]

        # If expiration date is close to unixtime 0, ban is permanent
	  if { $expire <= 0 } {
          set dateexpired "Eternity"
          set xlength "Infinity"
        } else {
          set xlength [duration [expr $expire - $added]])
        }

        putquick "NOTICE $nick :\0034\002$mask \002\003Banned by: \0033\002$setter\002\003 Ban Number:\002\0034 $counter"
        putquick "NOTICE $nick :\002Sentence\002: $dateadded. \002through\002 $dateexpired (\002Length\002: $xlength)." 
        putquick "NOTICE $nick :\002Reason\002: $reason."

	  # increment counter by 1
        incr counter
      }
    }
  }
}










